import router from '@/router/index';
import { useUserStore } from '@/store';
// @ts-ignore
import nprogress from 'nprogress'; //进度条
import 'nprogress/nprogress.css'; //进度条样式
nprogress.configure({ showSpinner: false }); //进度条加载时右侧的转圈不显示
import { useRouter } from 'vue-router';

const $router = useRouter();
const whiteList = ['/home/**'];
/** 路由前置守卫 */
router.beforeEach((to, from, next) => {
  document.title = ('多倍-' + to.meta.title) as string;
  next();
  const userStore = useUserStore();
  const token = userStore.user.token;
  if (token) {
    //执行获取用户信息
    userStore.getUserInfo(userStore.user.userId);
  } else {
    if (whiteList.includes(to.path)) {
      next();
    } else {
      $router.replace('/home/login');
    }
  }
});
/** 路由后置守卫 */
router.afterEach((to, from) => {
  nprogress.done(); //进度条结束
});
